package com.ckx.controller;

import com.ckx.domain.ResponseResult;
import com.ckx.domain.dto.ArticleAddDto;

import com.ckx.domain.dto.ArticleQueryDto;
import com.ckx.domain.dto.ArticleUpdateDto;
import com.ckx.domain.vo.ArticleVo;
import com.ckx.domain.vo.HotArticleVo;
import com.ckx.domain.vo.PageVo;
import com.ckx.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/content/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping
    public ResponseResult addArticle(@RequestBody @Validated ArticleAddDto articleAddDto){
        //todo 数据 vailidate校验
        articleService.addArticle(articleAddDto);
        return ResponseResult.okResult();

    }

    @GetMapping("/list")
    public ResponseResult listByPage(Integer pageNum, Integer pageSize, ArticleQueryDto articleQueryDto){
        PageVo pageVo = articleService.listByPage(pageNum, pageSize, articleQueryDto);
        return ResponseResult.okResult(pageVo);
    }

    @GetMapping("/{id}")
    public ResponseResult getArticleInfo(@PathVariable Long id){
        ArticleVo articleVo = articleService.getArticleInfo(id);
        return ResponseResult.okResult(articleVo);

    }

    @PutMapping
    public ResponseResult updateArticle(@RequestBody ArticleUpdateDto articleUpdateDto){
        articleService.updateArticle(articleUpdateDto);
        return ResponseResult.okResult();
    }

    @DeleteMapping("/{id}")
    public ResponseResult removeById(@PathVariable Long id){
        articleService.remove4DelFlag(id);
        return ResponseResult.okResult();
    }

}
